<script lang="ts" setup>
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import type { FormInstance, FormRules } from 'element-plus'

const loginFormRef = ref<FormInstance>()

const router = useRouter()

const loginForm = reactive({
  account: '',
  password: '',
  checked: false,
})

const rules = reactive<FormRules<typeof loginForm>>({
  account: [
    {
      required: true,
      message: '请输入用户名',
      trigger: 'blur',
    },
  ],
  password: [
    {
      required: true,
      message: '请输入密码',
      trigger: 'blur',
    },
  ],
})

const submitForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
  formEl.validate((valid) => {
    if (valid) {
      console.log('submit!')
      router.push('/')
    } else {
      console.log('error submit!')
    }
  })
}
</script>

<template>
  <div class="rounded-lg overflow-hidden shadow-lg">
    <div style="height: 150px; background-color: #027aff"></div>
    <div class="p-8 bg-white">
      <el-form
        ref="loginFormRef"
        :model="loginForm"
        :rules="rules"
        label-width="0"
        size="large"
        :show-message="false"
        inline-message
        status-icon
      >
        <el-form-item prop="account">
          <el-input
            v-model="loginForm.account"
            type="account"
            autocomplete="off"
            prefix-icon="User"
            placeholder="请输入账号/手机号码/邮箱地址"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="w-full" @click="submitForm(loginFormRef)">
            下一步
          </el-button>
        </el-form-item>
        <el-form-item style="margin: 0">
          <div class="flex justify-end w-full">
            <div>
              <el-link type="primary" underline="never" @click="router.push('/account/login')"
                >去登录</el-link
              >
              <el-divider direction="vertical" />
              <el-link type="primary" underline="never" @click="router.push('/account/register')"
                >去注册</el-link
              >
            </div>
          </div>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
